package com.wn.config;

import com.wn.intercept.ProjectHandlerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author yellow Docter
 * @date 2022 -07-12
 * @desc
 */
@Configuration
public class SpringmvcSupport implements WebMvcConfigurer {

    @Autowired
    private ProjectHandlerInterceptor projectHandlerInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //当访问/static/????时候，从/static目录下查找内容
        registry.addResourceHandler("/static/**").addResourceLocations("/static/");
    }

    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //拦截哪些请求
        registry.addInterceptor(projectHandlerInterceptor).addPathPatterns("/book/*");
    }
}
